# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 16:17
# @Author  : lt
# @Email   : lt@163.com
# @File    : add_ht.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from selenium.webdriver.support.select import Select
from time import sleep
class Add_Ht_Page(BasePage):
    # 定位添加合同按钮
    add_ht_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div > a')
    # 定位签约时间
    qianyue_time_locator = (By.ID, 'due_time')
    # 定位商机输入框
    shangji_button_locator = (By.ID, 'business_name')
    # 定位商机表
    tobdy_shangji_locator = (By.ID, 'data')
    # 定位商机Ok按钮
    ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')
    # 定位负责人输入按钮
    fuzeren_locator = (By.ID, 'owner_name')
    # 定位负责人表
    tobdy_fuzeren_locator = (By.ID, 'd_content')
    # 定位负责人勾选确定按钮
    queren_fuzeren_locator = (By.CSS_SELECTOR,
                              'body > div:nth-child(13) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span')
    # 定位合同金额输入框
    ht_jine_locator = (By.ID, 'price')
    # 定位合同开始时间
    start_time_locator = (By.ID, 'start_date')
    # 定位合同结束时间
    end_time_locator = (By.ID, 'end_date')
    # 定位条款和条件输入框
    tiiaojian_locator = (By.CSS_SELECTOR, '.ke-edit-iframe')
    # 定位描述输入框
    decription_locator = (By.ID, 'description')
    # 定位保存按钮
    baocun_locator = (By.NAME, 'submit')
    # 定位添加成功
    add_ht_succeful_locator = (By.XPATH, '/html/body/div[5]/div[2]')

    # 点击添加合同按钮
    def add_ht_click(self):
        self.driver.find_element(*self.add_ht_locator).click()

    # 输入签约时间
    def qianyue_time_shuru(self,qianyue_time):
        self.driver.find_element(*self.qianyue_time_locator).send_keys(qianyue_time)
    # 点击商机输入框
    def shangji_shuru(self):
        self.driver.find_element(*self.shangji_button_locator).click()
    # 选择商机
    def xuanze_shangji(self,shangji):
        tobdy_shangji = self.driver.find_element(*self.tobdy_shangji_locator)
        trs1 = tobdy_shangji.find_elements(By.TAG_NAME, 'tr')
        for i in trs1:
            tds1 = i.find_elements(By.TAG_NAME, 'td')
            if tds1[1].text == shangji:
            # 点击选择号的商机
                tds1[0].find_element(By.CSS_SELECTOR, 'input[name="business"]').click()
    # 点击确定
    def sahngji_queren(self):
        self.driver.find_element(*self.ok_locator).click()
    # 点击负责人输入框
    def fuzeren_shuru(self):
        self.driver.find_element(*self.fuzeren_locator).click()
        sleep(3)
    # 选择要输入的负责人
    def xuanze_fuzeren(self,name):
        tobdy_fuzeren = self.driver.find_element(*self.tobdy_fuzeren_locator)
        trs2 = tobdy_fuzeren.find_elements(By.TAG_NAME, 'tr')
        for e in trs2:
            tds2 = e.find_elements(By.TAG_NAME, 'td')
            if tds2[1].text == name:
                # 点击负责人
                tds2[0].find_element(By.CSS_SELECTOR, 'input[name="owner"]').click()
    # 点击确定
    def fuzeren_queren(self):
        self.driver.find_element(*self.queren_fuzeren_locator).click()
    # 输入合同金额
    def ht_jine_shuru(self,ht_jine):
        self.driver.find_element(*self.ht_jine_locator).send_keys(ht_jine)
    # 输入合同生效时间
    def start_time_shuru(self,start_time):
        self.driver.find_element(*self.start_time_locator).send_keys(start_time)
    # 输入合同失效时间
    def end_time_shuru(self,end_time):
        self.driver.find_element(*self.end_time_locator).send_keys(end_time)
    # 输入条款
    def tiaokuan(self,tiaojian):
        self.driver.find_element(*self.tiiaojian_locator).send_keys(tiaojian)
    # 输入描述信息
    def description_shuru(self,description):
        self.driver.find_element(*self.decription_locator).send_keys(description)
    # 点击保存按钮
    def baocun_click(self):
        self.driver.find_element(*self.baocun_locator).click()
    # 断言
    def tianjia_succeful(self):
        text = self.driver.find_element(*self.add_ht_succeful_locator).text
        return text